'''
Author: duliang thinktanker@163.com
Date: 2025-08-16 00:05:00
LastEditors: duliang thinktanker@163.com
LastEditTime: 2025-10-03 14:38:35
FilePath: 
Description: 
'''
from wxauto import WeChat
# from wxauto.msgs import FriendMessage
import time
import requests

wx = WeChat()

URL = 'http://192.168.11.123:5000'
URL = 'https://test.u96242.nyat.app:22654'
URL = 'http://192.168.15.101:5000'

# URL = 'http://192.168.43.172:5000'


# 消息处理函数
def on_message(msg, chat):
    # 示例1：将消息记录到本地文件
    now = int(time.time())
    print(msg)
    with open('msgs.txt', 'a', encoding='utf-8') as f:
        f.write(f'{now}:{msg.content}\n')
    if not "以下为新消息" in msg.content:
        resp = requests.get(
            f'{URL}/diancan?n=&d={msg.content}&t={int(time.time())}')
        print(resp.text)


# 添加监听，监听到的消息用on_message函数进行处理
wx.AddListenChat(nickname="就餐群", callback=on_message)
wx.AddListenChat(nickname="测试3群", callback=on_message)

# 保持程序运行
wx.KeepRunning()
